<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="154px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="去污等级数量" prop="CHLVLDEC001">
									<el-input
										size="medium"
										class="mediumForm"
										@input="numChange"
										v-model.number="ruleForm.CHLVLDEC001"
									></el-input>
								</el-form-item>

								<el-table ref="multipleTable" :data="ruleForm.allCHLVLDE" tooltip-effect="dark" border>
									<el-table-column prop="grage" label="等级" align="center" width="60"></el-table-column>
									<el-table-column prop="CHTIMDEC001" label="每个去污等级需要的时间" align="center" min-width="120">
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHTIMDEC001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHTIMDEC001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHTIMDEC001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="CHDSRFCT001"
										label="每个去污等级在减少剂量方面的效果"
										min-width="120"
										align="center"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHDSRFCT001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHDSRFCT001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHDSRFCT001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="CHCDFRM001"
										label="每个去污等级农场去污成本（元/hectare）"
										align="center"
										min-width="120"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHCDFRM001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHCDFRM001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHCDFRM001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="CHCDNFRM001"
										label="每个去污等级农田去污成本（元/人）"
										min-width="120"
										align="center"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHCDNFRM001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHCDNFRM001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHCDNFRM001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="CHFRFDL001"
										label="每个去污等级农田去污成本中劳动力所占比例"
										align="center"
										min-width="120"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHFRFDL001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHFRFDL001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHFRFDL001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="CHFRNFDL001"
										label="每个去污等级非农田去污成本中劳动力所占比例"
										min-width="120"
										align="center"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHFRNFDL001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHFRNFDL001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHFRNFDL001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="CHTFWKF001"
										label="每个去污等级农田去污工作时间的比例"
										min-width="120"
										align="center"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHTFWKF001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHTFWKF001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHTFWKF001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
									<el-table-column
										prop="CHTFWKNF001"
										label="每个去污等级非农田去污工作时间的比例"
										min-width="120"
										align="center"
									>
										<template slot-scope="scope">
											<el-form-item
												label-width="0px"
												:rules="rules.CHTFWKNF001"
												:prop="'allCHLVLDE.'+scope.$index+'.CHTFWKNF001'"
											>
												<el-input
													oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,20})?).*$/g, '$1')"
													class="bigForm"
													v-model="scope.row.CHTFWKNF001"
												></el-input>
											</el-form-item>
										</template>
									</el-table-column>
								</el-table>

								<el-form-item :style="{'margin-top':'20px'}" label="去污人工劳动力成本" prop="CHDLBCST001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHDLBCST001"
									>
										<template slot="append">元/人年</template>
									</el-input>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"

import { dome } from "@/utils/verify.js"
// import {
//     saveslbaseinfo,
//     slbaseinfo
// } from '../service.js';
export default {
	name: "aboutUs",
	props: {},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},

	data() {
		var C10E6315E7 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-6 || value > 3.15e7) {
				callback(new Error("输入范围为[1.0E-6，3.15E+7]"))
			} else {
				callback()
			}
		}

		var CHDLBCST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0 || value > 1.0e6) {
				callback(new Error("输入范围为[1.0，1.0E+6]"))
			} else {
				callback()
			}
		}
		return {
			activeTab: "3",

			ruleForm: {
				CHLVLDEC001: "1",
				CHDLBCST001: "35000.0",
				allCHLVLDE: [
					{
						grage: 1,
						CHTIMDEC001: "",
						CHDSRFCT001: "",
						CHCDFRM001: "",
						CHCDNFRM001: "",
						CHFRFDL001: "",
						CHFRNFDL001: "",
						CHTFWKF001: "",
						CHTFWKNF001: "",
					},
				],
			},
			rules: {
				CHLVLDEC001: [
					{
						validator: dome(1, 3),
						trigger: ["change", "blur"],
					},
				],
				CHTIMDEC001: [
					{
						validator: C10E6315E7,
						trigger: ["change", "blur"],
					},
				],
				CHDSRFCT001: [
					{
						validator: dome(1.0, 100.0),
						trigger: ["change", "blur"],
					},
				],
				CHCDFRM001: [
					{
						validator: dome(1.0, 1.0e5),
						trigger: ["change", "blur"],
					},
				],
				CHCDNFRM001: [
					{
						validator: dome(1.0, 1.0e5),
						trigger: ["change", "blur"],
					},
				],
				CHFRFDL001: [
					{
						validator: dome(0.0, 1.0),
						trigger: ["change", "blur"],
					},
				],
				CHFRNFDL001: [
					{
						validator: dome(0.0, 1.0),
						trigger: ["change", "blur"],
					},
				],
				CHTFWKF001: [
					{
						validator: dome(0.0, 1.0),
						trigger: ["change", "blur"],
					},
				],
				CHTFWKNF001: [
					{
						validator: dome(0.0, 1.0),
						trigger: ["change", "blur"],
					},
				],
				//去污工人劳动力成本
				CHDLBCST001: [
					{
						validator: CHDLBCST001,
						trigger: ["change", "blur"],
					},
				],
			},

			loading: false,
		}
	},
	computed: {
		...mapState({
			longterm_Data: (state) => state.token.longterm_Data,
			basic_Data: (state) => state.token.basic_Data,
			early_Data: (state) => state.token.early_Data,
		}),
	},
	mounted() {
		this.setData()
	},
	methods: {
		setData(){
			this.ruleForm.CHLVLDEC001=this.longterm_Data.CHLVLDEC001 
			this.ruleForm.allCHLVLDE = []
				for (let index = 0; index < this.longterm_Data.CHLVLDEC001; index++) { 
					let tempitem = {
						grage: index + 1,
						CHTIMDEC001: this.longterm_Data.CHTIMDEC001[index]? this.longterm_Data.CHTIMDEC001[index].toString():'',
						CHDSRFCT001:  this.longterm_Data.CHDSRFCT001[index]? this.longterm_Data.CHDSRFCT001[index].toString():'',
						CHCDFRM001:  this.longterm_Data.CHCDFRM001[index]? this.longterm_Data.CHCDFRM001[index].toString():'',
						CHCDNFRM001:  this.longterm_Data.CHCDNFRM001[index]? this.longterm_Data.CHCDNFRM001[index].toString():'',
						CHFRFDL001:  this.longterm_Data.CHFRFDL001[index]? this.longterm_Data.CHFRFDL001[index].toString():'',
						CHFRNFDL001:  this.longterm_Data.CHFRNFDL001[index]? this.longterm_Data.CHFRNFDL001[index].toString():'',
						CHTFWKF001:  this.longterm_Data.CHTFWKF001[index]? this.longterm_Data.CHTFWKF001[index].toString():'',
						CHTFWKNF001:  this.longterm_Data.CHTFWKNF001[index]? this.longterm_Data.CHTFWKNF001[index].toString():'',
					} 
					this.ruleForm.allCHLVLDE.push(tempitem)
				}
			this.ruleForm.CHDLBCST001=this.longterm_Data.CHDLBCST001?this.longterm_Data.CHDLBCST001:'35000'
		},
		numChange(value) { 
			if (value) {
				this.ruleForm.allCHLVLDE = []
				for (let index = 0; index < value; index++) { 
					let tempitem = {
						grage: index + 1,
						CHTIMDEC001: this.longterm_Data.CHTIMDEC001[index]? this.longterm_Data.CHTIMDEC001[index].toString():'',
						CHDSRFCT001:  this.longterm_Data.CHDSRFCT001[index]? this.longterm_Data.CHDSRFCT001[index].toString():'',
						CHCDFRM001:  this.longterm_Data.CHCDFRM001[index]? this.longterm_Data.CHCDFRM001[index].toString():'',
						CHCDNFRM001:  this.longterm_Data.CHCDNFRM001[index]? this.longterm_Data.CHCDNFRM001[index].toString():'',
						CHFRFDL001:  this.longterm_Data.CHFRFDL001[index]? this.longterm_Data.CHFRFDL001[index].toString():'',
						CHFRNFDL001:  this.longterm_Data.CHFRNFDL001[index]? this.longterm_Data.CHFRNFDL001[index].toString():'',
						CHTFWKF001:  this.longterm_Data.CHTFWKF001[index]? this.longterm_Data.CHTFWKF001[index].toString():'',
						CHTFWKNF001:  this.longterm_Data.CHTFWKNF001[index]? this.longterm_Data.CHTFWKNF001[index].toString():'',
					} 
					this.ruleForm.allCHLVLDE.push(tempitem)
				} 
			}
		},
		submitFun() {
			this.$refs.form.validate((valid) => {
				if (valid) { 
					let tempdata = JSON.parse(
						JSON.stringify(this.longterm_Data)
					) 
					tempdata.CHLVLDEC001 = this.ruleForm.CHLVLDEC001?parseInt(this.ruleForm.CHLVLDEC001):0

					tempdata.CHTIMDEC001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHTIMDEC001)
						}
					)
					tempdata.CHDSRFCT001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHDSRFCT001)
						}
					)
					tempdata.CHCDFRM001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHCDFRM001)
						}
					)
					tempdata.CHCDNFRM001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHCDNFRM001)
						}
					)
					tempdata.CHFRFDL001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHFRFDL001)
						}
					)
					tempdata.CHFRNFDL001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHFRNFDL001)
						}
					)
					tempdata.CHTFWKF001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHTFWKF001)
						}
					)
					tempdata.CHTFWKNF001 = this.ruleForm.allCHLVLDE.map(
						(item) => {
							return parseFloat(item.CHTFWKNF001)
						}
					)

					tempdata.CHDLBCST001 = parseFloat(this.ruleForm.CHDLBCST001) 
					tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_longterm_Data", tempdata) 
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "CHANGQI",
						submitjson: JSON.stringify(tempdata),
					} 
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => { 
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "保存失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "保存成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_longterm_showTab",
						this.activeTab
					)
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>